/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.tools;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 *
 * @author Austin
 */
public class SplitJsonUserArray {
     public static void main(String[] args) throws FileNotFoundException, IOException {
        String sJson = "{\"record_meta\":[{\"name\":\"message_id\",\"type\":\"string\"},{\"name\":\"url\",\"type\":\"string\"},{\"name\":\"content\",\"type\":\"string\"},{\"name\":\"user_id\",\"type\":\"string\"},{\"name\":\"is_retweet\",\"type\":\"int\"},{\"name\":\"origin_user_name\",\"type\":\"string\"},{\"name\":\"origin_message_id\",\"type\":\"string\"},{\"name\":\"create_time\",\"type\":\"string\"},{\"name\":\"crawl_time\",\"type\":\"timestamp\"},{\"name\":\"favorited_count\",\"type\":\"int64\"},{\"name\":\"retweet_count\",\"type\":\"int64\"},{\"name\":\"user_name\",\"type\":\"string\"},{\"name\":\"reply_to_screen_name\",\"type\":\"string\"},{\"name\":\"mention_users\",\"type\":\"string\"},{\"name\":\"location\",\"type\":\"string\"}],\"record_list\":[{\"message_id\":\"805476342150164480\",\"url\":\"https://twitter.com/gonzales7661/status/805476342150164480\",\"content\":\"People will question your why. At times, you will question your why. Just never forget WHY you started!\",\"user_id\":\"61070071\",\"is_retweet\":\"true\",\"origin_user_name\":\"CoachSalgeHCC\",\"origin_message_id\":\"805235445227470850\",\"create_time\":\"2016-12-04 02:21:05\",\"crawl_time\":\"2016-12-25 07:40:31.0\",\"favorited_count\":\"1\",\"retweet_count\":\"0\",\"user_name\":\"gonzales7661\",\"reply_to_screen_name\":\"null\",\"mention_users\":\"\",\"location\":\"null\"}]}";
        StringBuffer sb = new StringBuffer("");
        new SplitJsonArray().paserContent(sJson);
        FileReader reader = new FileReader("D://test_imsg");
        BufferedReader br = new BufferedReader(reader);

        String str = null;

        while ((str = br.readLine()) != null) {
            sb.append(str + "/n");

            System.out.println(str);
            new SplitJsonArray().paserContent(str);
        }

        br.close();
        reader.close();

    }

    private ArrayList<String> user_id = new ArrayList<>();
    private ArrayList<String> user_name = new ArrayList<>();
    private ArrayList<String> gender = new ArrayList<>();
    private ArrayList<String> birthday = new ArrayList<>();
    private ArrayList<String> bloodType = new ArrayList<>();
    private ArrayList<String> emotionAptitude = new ArrayList<>();
    private ArrayList<String> relationshipStatus = new ArrayList<>();
    private ArrayList<String> Hometown = new ArrayList<>();
    private ArrayList<String> work = new ArrayList<>();
    private ArrayList<String> Education = new ArrayList<>();
    private ArrayList<String> language = new ArrayList<>();
    private ArrayList<String> crawl_time = new ArrayList<>();
    private ArrayList<String> image = new ArrayList<>();


    private int count = 1;
    private JSONObject jsonString = null;

    public void paserContent(String str) {
        user_id.clear();
        user_name.clear();
        gender.clear();
        birthday.clear();
        bloodType.clear();
        emotionAptitude.clear();
        relationshipStatus.clear();
        Hometown.clear();
        work.clear();
        Education.clear();
        language.clear();
        crawl_time.clear();
        image.clear();
        jsonString = JSONObject.fromObject(str);
//		System.out.println(jsonString.get("WxId"));
//		System.out.println(jsonString.get("SendTime"));
        JSONArray jaArray = jsonString.getJSONArray("record_list");
        count = jaArray.size();
        for (int i = 0; i < jaArray.size(); i++) {
            JSONObject jo = (JSONObject) jaArray.get(i);
            //System.out.println(jo.get("MediaUrl"));
            user_id.add(jo.get("user_id").toString());
            user_name.add(jo.get("user_name").toString());
            gender.add(jo.get("gender").toString());
            birthday.add(jo.get("birthday").toString());
            bloodType.add(jo.get("bloodType").toString());
            emotionAptitude.add(jo.get("emotionAptitude").toString());
            relationshipStatus.add(jo.get("relationshipStatus").toString());
            Hometown.add(jo.get("Hometown").toString());
            work.add(jo.get("work").toString());
            Education.add(jo.get("Education").toString());
            language.add(jo.get("language").toString());
            crawl_time.add(jo.get("crawl_time").toString());
            image.add(jo.get("image").toString());


        }
        
}

    public ArrayList<String> getUser_id() {
        return user_id;
    }

    public ArrayList<String> getUser_name() {
        return user_name;
    }

    public ArrayList<String> getGender() {
        return gender;
    }

    public ArrayList<String> getBirthday() {
        return birthday;
    }

    public ArrayList<String> getBloodType() {
        return bloodType;
    }

    public ArrayList<String> getEmotionAptitude() {
        return emotionAptitude;
    }

    public ArrayList<String> getRelationshipStatus() {
        return relationshipStatus;
    }

    public ArrayList<String> getHometown() {
        return Hometown;
    }

    public ArrayList<String> getWork() {
        return work;
    }

    public ArrayList<String> getEducation() {
        return Education;
    }

    public ArrayList<String> getLanguage() {
        return language;
    }

    public ArrayList<String> getCrawl_time() {
        return crawl_time;
    }

    public ArrayList<String> getImage() {
        return image;
    }
    

    public int getCount() {
        return count;
    }

    public JSONObject getJsonString() {
        return jsonString;
    }
}